/// 请求 * 登录

import type { ILogoutLogParams, LoginInfo, LoginParams, LoginProject, LoginToken } from './types'
import { request } from '@/helpers'

/**
 * 登录
 */
export function apiLogin(params: LoginParams) {
  const url = '/hdpu-auth/user/delivery/login'
  return request<LoginToken>(
    url,
    {
      method: 'POST',
      data: { ...params, platformType: 10, deviceType: 'PC' },
    },
    'result',
  )
}

/**
 * 登出
 */
export function apiLogout() {
  const url = '/hdpu-auth/user/delivery/logout'
  return request(
    url,
    {
      method: 'POST',
    },
    'result',
  )
}

/**
 * 登录信息
 */
export function apiLoginInfo() {
  const url = '/hdpu-rbac-delivery/deliver/user/loginInfo'
  return request<LoginInfo>(
    url,
    {
      method: 'POST',
      data: { platformType: 10, clientType: 1 }, //* 客户端类型: 1-web; 2-小程序; */ clientType: number
    },
    'data',
  )
}

/**
 * 登录日志
 */
export function apiLoginLog() {
  const url = '/hdpu-rbac-delivery/hdpuUser/generateLoginLog'
  return request(url, {
    method: 'POST',
  })
}

/**
 * 登出日志
 */
export function apiLogoutLog(data: Partial<ILogoutLogParams>) {
  const url = '/hdpu-rbac-dev/hdpuUser/generateLogoutLog'
  return request(url, {
    method: 'POST',
    data,
  })
}

/**
 * 令牌 刷新
 */
export function apiRefreshToken(refreshToken: string) {
  const url = '/hdpu-auth/token/refreshToken'
  return request<LoginToken>(
    url,
    {
      method: 'POST',
      data: { refreshToken },
    },
    'result',
  )
}

/**
 * 登录项目列表 查询
 */
export function apiQueryLoginProjects() {
  const url = '/hdpu-customer-manager/deliver/project/queryLoginUserProject'
  return request<LoginProject[]>(url, {
    method: 'GET',
  })
}

export function apiMergeLoginProject(projectId: number) {
  const url = `/hdpu-rbac-delivery/deliver/user/updateUserLastProjectId/${projectId}`
  return request(
    url,
    {
      method: 'POST',
    },
    'result',
  )
}

export * from './types'
